#include <stdio.h>
#include <unistd.h>
#include <stdlib.h>
#include <sys/types.h>
#define _GNU_SOURCE
#include <sys/mman.h>
#include <string.h>
#include <fcntl.h>

#define	DEVICE	"/dev/memio0"

int main ( int argc, char* argv[] ) {
	void *  memory = NULL;
	long sz = sysconf(_SC_PAGESIZE);
	int dd = open( DEVICE, O_RDWR );
	char symb = 0;
	if ( dd == -1 ) {
		perror( "Can't open file " DEVICE );
		exit( EXIT_FAILURE );
	}
	memory = mmap( NULL, sz, PROT_READ|PROT_WRITE, MAP_SHARED, dd, 2*sz );
	if (memory==MAP_FAILED) {
		perror( "Can't map file " DEVICE );
		exit( EXIT_FAILURE );
	}
	printf( "First 4 bytes: %c,%c,%c,%c\n", *((char*)(memory)), *((char*)(memory+1)), *((char*)(memory+2)), *((char*)(memory+3)) );
	symb = *((char*)memory);
	symb = (++symb > 'Z') ? 'A' : symb;
	*((char*)memory) = symb;
	symb = *((char*)(memory+512));
	symb += 1;
	if ( symb < '0' || symb > '9' ) {
		symb = '0';
	}
	*((char*)(memory+512)) = symb;
	munmap( memory, sz );
	return 0;
}
